import React from "react";
import judgePath from '../../service/judgePath';
import {Breadcrumb} from "antd";
import {Link} from "react-router-dom";
import API from '../../api/api'
let config = require("../../util/config").config

export default class BreadCrumb extends React.Component{
    constructor(props) {
        super(props);
        console.log("component breadCrumb constructor props",this.props)
    }

    UNSAFE_componentWillReceiveProps(nextProps, nextContext) {
        console.log("component breadCrumb UNSAFE_componentWillReceiveProps nextProps",nextProps)
        this.breadArr = [];
    }

    breadArr = [];

    contentFresh(){
        let path = this.props.routeInfo;
        // if(store.getState().breadCrumbList!=undefined){
        //     let num = 0;
        //     return store.getState().breadCrumbList.map(item => {
        //             num = num+1;
        //             return (
        //                 <Breadcrumb.Item key={num}>{item.name}</Breadcrumb.Item>
        //             )
        //         }
        //     )
        // }
        // else


        //1、首页管理
        if(path=="/eip/index"){
            this.breadArr.push(
                <Breadcrumb.Item>
                    <span>{config.eip_index}</span>
                </Breadcrumb.Item>
            )
        }
        //1.1、公告列表和活动列表
        else if(path=="/eip/table/notice" || path == "/eip/table/activity"){
            this.breadArr.push(
                <Breadcrumb.Item>
                    <Link to="/eip/index">{config.eip_index}</Link>
                </Breadcrumb.Item>
            )
            if(path=="/eip/table/notice"){
                this.breadArr.push(
                    <Breadcrumb.Item>
                        <span>{config.eip_table_notice}</span>
                    </Breadcrumb.Item>
                )
            }else if(path=="/eip/table/activity"){
                this.breadArr.push(
                    <Breadcrumb.Item>
                        <span>{config.eip_table_activity}</span>
                    </Breadcrumb.Item>
                )
            }
        }
        //1.1.1、公告详情和活动详情
        else if(path.indexOf("/eip/file/notice")>=0 || path.indexOf("/eip/file/activity")>=0){
            this.breadArr.push(
                <Breadcrumb.Item>
                    <Link to="/eip/index">{config.eip_index}</Link>
                </Breadcrumb.Item>
            )
            if(path.indexOf("/eip/file/notice")>=0){
                this.breadArr.push(
                    <Breadcrumb.Item>
                        <Link to="/eip/table/notice">{config.eip_table_notice}</Link>
                    </Breadcrumb.Item>
                )
                this.breadArr.push(
                    <Breadcrumb.Item>
                        <span>{config.eip_file_notice}</span>
                    </Breadcrumb.Item>
                )
            }else if(path.indexOf("/eip/file/activity")>=0){
                this.breadArr.push(
                    <Breadcrumb.Item>
                        <Link to="/eip/table/activity">{config.eip_table_activity}</Link>
                    </Breadcrumb.Item>
                )
                this.breadArr.push(
                    <Breadcrumb.Item>
                        <span>{config.eip_file_activity}</span>
                    </Breadcrumb.Item>
                )
            }
        }


        //2、用户浏览模块
        else if(path.indexOf("/eip/module/")>=0){
            let arr = path.split("/");
            let item = arr[3].split("&")
            let type = item[0];
            if(type=="folder"){
                type="folder-d"
            }
            let id = item[1];
            let breadCrumbList = JSON.parse(sessionStorage.getItem("breadCrumbList"));
            breadCrumbList.map(item=>{
                this.breadArr.push(
                    <Breadcrumb.Item>
                        <Link to={`/eip/module/folder&${item.ID}`}>
                            <span>{item.NAME}</span>
                        </Link>
                    </Breadcrumb.Item>
                )
            })
            this.breadArr.reverse()
        }
        else if(path.indexOf("/eip/table/file&")>=0 || path.indexOf("/eip/table/article&")>=0 || path.indexOf("/eip/table/folder&")>=0){
            let arr = path.split("/");
            let item = arr[3].split("&")
            let type = item[0];
            if(type=="file"){
                type="file-d"
            }else if(type=="article"){
                type="article-d"
            }
            let id = item[1];
            let breadCrumbList = JSON.parse(sessionStorage.getItem("breadCrumbList"));
            breadCrumbList.map(item=>{
                if(item.TYPE=="folder-d"){
                    this.breadArr.push(
                        <Breadcrumb.Item>
                            <Link to={`/eip/module/folder&${item.ID}`}>
                                <span>{item.NAME}</span>
                            </Link>
                        </Breadcrumb.Item>
                    )
                }else if(item.TYPE=="file-d" || item.TYPE=="article-d" || item.TYPE=="folder"){
                    if(item.TYPE=="file-d"){
                        item.TYPE="file"
                    }else if(item.TYPE=="article-d"){
                        item.TYPE="article"
                    }
                    this.breadArr.push(
                        <Breadcrumb.Item>
                            <Link to={`/eip/table/${item.TYPE}&${item.ID}`}>
                                <span>{item.NAME}</span>
                            </Link>
                        </Breadcrumb.Item>
                    )
                }
            })
            this.breadArr.reverse()
        }
        else if(path.indexOf("/eip/file/file/")>=0 || path.indexOf("/eip/file/article/")>=0 ){
            let arr = path.split("/");
            let type = arr[3];
            let id = arr[4];
            let breadCrumbList = JSON.parse(sessionStorage.getItem("breadCrumbList"));
            breadCrumbList.map(item=>{
                if(item.TYPE=="folder-d"){
                    this.breadArr.push(
                        <Breadcrumb.Item>
                            <Link to={`/eip/module/folder&${item.ID}`}>
                                <span>{item.NAME}</span>
                            </Link>
                        </Breadcrumb.Item>
                    )
                }else if(item.TYPE=="file-d" || item.TYPE=="article-d" || item.TYPE=="folder"){
                    if(item.TYPE=="file-d"){
                        item.TYPE="file"
                    }else if(item.TYPE=="article-d"){
                        item.TYPE="article"
                    }
                    this.breadArr.push(
                        <Breadcrumb.Item>
                            <Link to={`/eip/table/${item.TYPE}&${item.ID}`}>
                                <span>{item.NAME}</span>
                            </Link>
                        </Breadcrumb.Item>
                    )
                }else if(item.TYPE=="file" || item.TYPE=="article"){
                    this.breadArr.push(
                        <Breadcrumb.Item>
                            <span>{item.NAME}</span>
                        </Breadcrumb.Item>
                    )
                }
            })
            this.breadArr.reverse()
        }


        //3、后台管理
        else if(path=="/eip/manage"){
            this.breadArr.push(
                <Breadcrumb.Item>
                    <span>{config.eip_manage}</span>
                </Breadcrumb.Item>
            )
        }
        //3.1、模塊管理:folder&0
        else if(path.indexOf("/eip/module-manage/folder&0")>=0){
            this.getManageBreadCrumbsCommon()
        }
        else if(path.indexOf("/eip/module-manage/")>=0){
        //3.1.1、模块管理:!=folder&0
            let arr = path.split("/");
            let item = arr[3].split("&");
            let type = item[0];
            if(type=="folder"){
                type = "folder-d"
            }else if(type=="file"){
                type = "file-d"
            }else if(type=="folder-f"){
                type = "folder"
            }else if(type=="article"){
                type = "article-d"
            }else if(type=="page"){
                type = "page"
            }
            let id = item[1];
            //接口获取面包屑节点数组
            let breadCrumbList = API.getBreadCrumbs({type,id})
            //反转数组顺序
            breadCrumbList.reverse()
            //获取通用的面包屑节点
            this.getManageBreadCrumbsCommon()
            //遍历接口得到的面包屑节点数组
            breadCrumbList.map(item=>{
                if(item.TYPE=="folder-d"){
                    this.breadArr.push(
                        <Breadcrumb.Item>
                            <Link to={`/eip/module-manage/folder&${item.ID}`}>
                                <span>{item.NAME}</span>
                            </Link>
                        </Breadcrumb.Item>
                    )
                }else if(item.TYPE=="folder"){
                    this.breadArr.push(
                        <Breadcrumb.Item>
                            <Link to={`/eip/module-manage/folder-f&${item.ID}`}>
                                <span>{item.NAME}</span>
                            </Link>
                        </Breadcrumb.Item>
                    )
                }else if(item.TYPE=="file-d"){
                    this.breadArr.push(
                        <Breadcrumb.Item>
                            <Link to={`/eip/module-manage/file&${item.ID}`}>
                                <span>{item.NAME}</span>
                            </Link>
                        </Breadcrumb.Item>
                    )
                }else if(item.TYPE=="article-d"){
                    this.breadArr.push(
                        <Breadcrumb.Item>
                            <Link to={`/eip/module-manage/article&${item.ID}`}>
                                <span>{item.NAME}</span>
                            </Link>
                        </Breadcrumb.Item>
                    )
                }else if(item.TYPE=="page"){
                    this.breadArr.push(
                        <Breadcrumb.Item>
                            <span>{item.NAME}</span>
                        </Breadcrumb.Item>
                    )
                }
            })
        }
        //3.2、角色管理、用戶管理、首頁管理、日誌管理、公告管理、活動管理
        else if(judgePath(path)){
            this.breadArr.push(
                <Breadcrumb.Item>
                    <Link to="/eip/manage">{config.eip_manage}</Link>
                </Breadcrumb.Item>
            )
            if(path=="/eip/role"){
                this.breadArr.push(
                    <Breadcrumb.Item>
                        <span>{config.eip_role}</span>
                    </Breadcrumb.Item>
                )
            }else if(path=="/eip/user"){
                this.breadArr.push(
                    <Breadcrumb.Item>
                        <span>{config.eip_user}</span>
                    </Breadcrumb.Item>
                )
            }else if(path=="/eip/index-manage"){
                this.breadArr.push(
                    <Breadcrumb.Item>
                        <span>{config.eip_indexManage}</span>
                    </Breadcrumb.Item>
                )
            }else if(path=="/eip/log"){
                this.breadArr.push(
                    <Breadcrumb.Item>
                        <span>{config.eip_log}</span>
                    </Breadcrumb.Item>
                )
            }else if(path=="/eip/notice-manage"){
                this.breadArr.push(
                    <Breadcrumb.Item>
                        <span>{config.eip_noticeManage}</span>
                    </Breadcrumb.Item>
                )
            }else if(path=="/eip/activity-manage"){
                this.breadArr.push(
                    <Breadcrumb.Item>
                        <span>{config.eip_activityManage}</span>
                    </Breadcrumb.Item>
                )
            }else if(path=="/eip/subscribe"){
                this.breadArr.push(
                    <Breadcrumb.Item>
                        <span>{config.eip_subscribe}</span>
                    </Breadcrumb.Item>
                )
            }else if(path=="/eip/subscribeLog"){
                this.breadArr.push(
                    <Breadcrumb.Item>
                        <span>{config.eip_subscribeLog}</span>
                    </Breadcrumb.Item>
                )
            }else if(path=='/eip/module-manage-log'){
                this.breadArr.push(
                    <Breadcrumb.Item>
                        <span>{config.eip_moduleLog}</span>
                    </Breadcrumb.Item>
                )
            }else if(path=='/eip/loginLog'){
                this.breadArr.push(
                    <Breadcrumb.Item>
                        <span>{config.eip_loginLog}</span>
                    </Breadcrumb.Item>
                )
            }else if(path=='/eip/activityLog'){
                this.breadArr.push(
                    <Breadcrumb.Item>
                        <span>{config.eip_activityLog}</span>
                    </Breadcrumb.Item>
                )
            }else if(path=='/eip/noticeLog'){
                this.breadArr.push(
                    <Breadcrumb.Item>
                        <span>{config.eip_noticeLog}</span>
                    </Breadcrumb.Item>
                )
            } else if(path=='/eip/item-manage'){
                this.breadArr.push(
                    <Breadcrumb.Item>
                        <span>{config.eip_item_manage}</span>
                    </Breadcrumb.Item>
                )
            }
        }

        if(path.indexOf("/eip/activity-manage-content")>=0 || path.indexOf("/eip/notice-manage-content")>=0){
            this.breadArr.push(
                <Breadcrumb.Item>
                    <Link to="/eip/manage">{config.eip_manage}</Link>
                </Breadcrumb.Item>
            )
            if(path.indexOf("/eip/activity-manage-content")>=0){
                this.breadArr.push(
                    <Breadcrumb.Item>
                        <Link to="/eip/activity-manage">{config.eip_activityManage}</Link>
                    </Breadcrumb.Item>
                )
                this.breadArr.push(
                    <Breadcrumb.Item>
                        <span>{config.eip_file_activity}</span>
                    </Breadcrumb.Item>
                )
            }else if(path.indexOf("/eip/notice-manage-content")>=0){
                this.breadArr.push(
                    <Breadcrumb.Item>
                        <Link to="/eip/notice-manage">{config.eip_noticeManage}</Link>
                    </Breadcrumb.Item>
                )
                this.breadArr.push(
                    <Breadcrumb.Item>
                        <span>{config.eip_file_notice}</span>
                    </Breadcrumb.Item>
                )
            }
        }

        return this.breadArr;
    }

    getManageBreadCrumbsCommon=()=>{
        this.breadArr.push(
            <Breadcrumb.Item>
                <Link to="/eip/manage">
                    <span>{config.eip_manage}</span>
                </Link>
            </Breadcrumb.Item>
        )
        this.breadArr.push(
            <Breadcrumb.Item>
                <Link to={"/eip/module-manage/folder&0"}>
                    <span>模块管理</span>
                </Link>
            </Breadcrumb.Item>
        )
    }

    render() {

        return(
            <Breadcrumb separator=">" style={{margin: '0.5rem 0'}}>
                {this.contentFresh()}
            </Breadcrumb>
        )
    }
}
